<?php
/**
 * Created by PhpStorm.
 * User: zhulihulian
 * Date: 2017/7/5
 * Time: 12:08
 */

namespace app\ice\model;

use think\Model;

class UserAddress extends Model {
    protected $table = 'ig_user_address';
    protected $pk = 'address_id';

    public function getAddressList($where){
    	return $this->where('uid',$where['uid'])->select();
    }

    public function getAddressDefalt($where){
        $data = false;
    	$data = $this->where('uid',$where['uid'])->where('isDefault',1)->find();
        if(!$data){
            $data = $this->where('uid',$where['uid'])->order('address_id desc')->find();
            if($data){
                $data['isDefault'] = 1;
            }
            
        }
        return $data;
    }
    
    public function getAddressDetail($where){
    	return $this->where('uid',$where['uid'])->where('address_id',$where['id'])->find();
    }
}